package com.isoft.illustrationsdraw.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isoft.illustrationsdraw.entity.Admin;
import com.isoft.illustrationsdraw.entity.ReportStatusLog;
import com.isoft.illustrationsdraw.mapper.AdminMapper;
import com.isoft.illustrationsdraw.service.AdminService;
import com.isoft.illustrationsdraw.service.CommentService;
import com.isoft.illustrationsdraw.service.UserService;
import com.isoft.illustrationsdraw.service.IllustrationService;
import com.isoft.illustrationsdraw.service.ReportService;

import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    private final UserService userService;
    private final IllustrationService illustrationService;
    private final CommentService commentService;
    private final ReportService reportService;

    public AdminServiceImpl(ReportService reportService, UserService userService, IllustrationService illustrationService, CommentService commentService) {
        this.commentService = commentService;
        this.userService = userService;
        this.illustrationService = illustrationService;
        this.reportService = reportService;
    }

    @Override
    public boolean attemptBanSomeone(Long id) {
        var user = userService.getById(id);
        user.setIsBanned(1);
        return userService.save(user);

    }

    @Override
    public boolean lockIllustration(Long id) {
        var illustration = illustrationService.getById(id);
        illustration.setVisibility(-1);
        return illustrationService.save(illustration);
    }

    @Override
    public boolean forceToDeleteComment(Long id) {
        return commentService.removeById(commentService.removeById(id));
    }

    @Override
    public boolean processReport(ReportStatusLog newLog) {
        return reportService.updateReportAndLog(newLog);
    }
    
}
